package com.yisu.expressway.network;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.graphics.drawable.BuildConfig;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.yisu.expressway.application.ExApplication;
import com.yisu.expressway.utils.AppUpdateUtils;

/**
 * Created by Administrator on 2016/9/14 0014.
 */
public class NetworkConfig {

    public static String mClientVersion = null;
    private static String sUserAgent = "";

    /**
     * 获取自定义 UserAgent 字符串
     * format: Android__App版本号_操作系统版本_设备型号
     * @return
     */
    public static String getWebUserAgent() {
        if (TextUtils.isEmpty(sUserAgent)) {
//            String imei = ((TelephonyManager) ExApplication.getInstance()
//                    .getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
            StringBuilder sb = new StringBuilder();
            sb.append("Android_")
                    .append(AppUpdateUtils.getAppVersionName(ExApplication.getInstance())).append('_')
                    .append(Build.VERSION.RELEASE).append('_')	//操作系统版本
                    .append(Build.MODEL);	//设备型号

            sUserAgent = sb.toString();
        }
        return sUserAgent;
    }

    public static int getAppVersionCode(Context context){
        int versionCode =0;
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionCode = pi.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionCode;
    }
}
